// src/main/java/org/csu/mybigpro/config/WebSocketConfig.java
package org.csu.mybigpro.config;

import org.csu.mybigpro.handler.SpeechWebSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private SpeechWebSocketHandler speechWebSocketHandler; // 自动注入我们即将创建的处理器

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(speechWebSocketHandler, "/api/speech-stream")
                .setAllowedOrigins("*"); // 允许所有来源的连接，方便开发
    }
}